package com.cloudfun.campusshare.configuration.jpa;

import com.cloudfun.campusshare.common.response.PageResult;
import com.cloudfun.campusshare.configuration.jpa.util.PropertyFilter;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import java.io.Serializable;
import java.util.List;

/**
 * @author wangxiyuan
 * @description
 * @createDate 2021/5/19 17:47
 **/
public interface GaodaoRepository<T, ID extends Serializable> extends JpaRepository<T, ID> , JpaSpecificationExecutor<T> {
    T findOneByProperty(String property,String value);

    List<T> findListByProperty(String property,String value);

    T findOneByFilters(List<PropertyFilter> propertyFilters);

    List<T> findListByFilters(List<PropertyFilter> propertyFilters);

    Long findCount(String sql);
    /**
     * 根据原生sql查询单个对象 不能查询
     * @param sqlString sql语句
     * @param clazz 类 提供的DTO字段名称
     * @param <X>
     * @return
     */
    <X> X findSingleQuery(String sqlString, Class<X> clazz);

    <X> X findSingleQuery(String sqlString, Object[] objs, Class<X> clazz);

    /**
     * 根据原生sql查询多个对象
     * @param sqlString
     * @param objs 参数
     * @param clazz 类
     * @param <X>
     * @return
     */
    <X> List<X> findNativeNamedQuery(String sqlString, Object[] objs, Class<X> clazz);

    /**
     * 分页查询
     * @param sqlString
     * @param page
     * @param clazz
     * @param <X>
     * @return
     */
    <X> PageResult<X> findNativeNamedQuery(String sqlString, PageRequest page, Class<X> clazz);

    <X> PageResult<X> findNativeNamedQuery(String sqlString, Object[] objs, PageRequest page, Class<X> clazz);
}
